<template>
    <div class="mainDiv">
        <div class="rowHead">
            <el-button type="success" icon="plus" @click="add">新增</el-button>
        </div>
        <el-table :data="list" :stripe="true" height="100%">
            <el-table-column prop="id" label="ID"></el-table-column>
            <el-table-column prop="name" label="名称"></el-table-column>
            <el-table-column prop="type" label="类型">
              <template slot-scope="scope">
                    <el-tag v-if="scope.row.type === 1">产品</el-tag>
                    <el-tag type="success" v-else>项目</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="remarks" label="描述"></el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button-group>
                        <el-tooltip content="编辑" placement="left" :open-delay="800">
                            <el-button type="warning" icon="el-icon-edit" size="mini" @click="edit(scope.row)"></el-button>
                        </el-tooltip>
                        <el-tooltip content="删除" placement="top" :open-delay="800">
                            <el-button type="danger" icon="el-icon-h-del" size="mini" @click="deleteone(scope.row.id)"></el-button>
                        </el-tooltip>
                    </el-button-group>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import C from '@/common/common.js'

export default {
  name: 'permissionLevel',
  data () {
    return {
      list: []
    }
  },
  methods: {
    add: async function () {
      let data = await C.openBrowserWindow('/addchildclass', {}, {
        transparent: true,
        frame: false,
        width: 420,
        height: 390,
        useSpa: false,
        spaModel: 'organization'
      })
      if (data) {
        C.success(data.data)
        this.getList()
      }
    },
    edit: async function (row) {
      let data = await C.openBrowserWindow('/addchildclass', { row: row }, {
        transparent: true,
        frame: false,
        width: 420,
        height: 390,
        useSpa: false,
        spaModel: 'organization'
      })
      if (data) {
        C.success(data.data)
        this.getList()
      }
    },
    deleteone: function (id) {
      C.confirm('确定删除该类？', async () => {
        let data = await C.ajax('/organization/subproconf/deleteone', { id: id }, 'post')
        if (data) {
          C.success(data.data)
          this.getList()
        }
      })
    },
    getList: async function () {
      let data = await C.ajax('/organization/subproconf/getlists')
      if (data) {
        console.log(data)
        this.list = data
      }
    }
  },
  mounted: function () {
    this.getList()
  }
}
</script>